package com.corona.game;

import com.corona.Game;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Locale;

/* compiled from: Battle.java */
/* loaded from: pokewilds.jar:com/pkmngen/game/CheckEndOfBattle.class */
public class CheckEndOfBattle extends Action {
    public Action.Layer layer = Action.Layer.gui_129;

    public CheckEndOfBattle(Action nextAction) {
        super(new Object[0]);
        this.nextAction = nextAction;
    }

    @Override // com.corona.game.Action
    public String getCamera() {
        return "gui";
    }

    @Override // com.corona.game.Action
    public Action.Layer getLayer() {
        return this.layer;
    }

    @Override // com.corona.game.Action
    public void step(Game game) {
        game.actionStack.remove(this);
        if (game.battle.oppPokemon.currentStats.get("hp").intValue() <= 0) {
            Action nextAction = new Action(new Object[0]) { // from class: com.corona.game.CheckEndOfBattle.1
                @Override // com.corona.game.Action
                public String getCamera() {
                    return "gui";
                }
            };
            ArrayList<Pokemon> participated = new ArrayList<>();
            Iterator<Pokemon> it = game.player.pokemon.iterator();
            while (it.hasNext()) {
                Pokemon pokemon = it.next();
                if (pokemon.participatedInBattle && pokemon.currentStats.get("hp").intValue() > 0 && pokemon.level < 100) {
                    if (pokemon == game.player.currPokemon) {
                        participated.add(0, pokemon);
                    } else {
                        participated.add(pokemon);
                    }
                }
            }
            if (!participated.isEmpty()) {
                Iterator<Pokemon> it2 = participated.iterator();
                while (it2.hasNext()) {
                    Pokemon pokemon2 = it2.next();
                    int exp = game.battle.calcFaintExp(participated.size());
                    pokemon2.exp += exp;
                    if (pokemon2 != game.player.currPokemon) {
                        nextAction.append(new DisplayText.Clear(game, null));
                        nextAction.append(new WaitFrames(game, 3, null));
                    }
                    nextAction.append(new DisplayText(game, pokemon2.nickname.toUpperCase(Locale.ROOT) + " gained " + String.valueOf(exp) + " EXP. Points!", (String) null, true, true, (Action) null));
                    if (pokemon2 == game.player.currPokemon) {
                        nextAction.append(new GainExpAnimationGen2(pokemon2, null));
                    } else {
                        nextAction.append(new GainExpAnimation(pokemon2, null));
                    }
                }
                Iterator<Pokemon> it3 = participated.iterator();
                while (it3.hasNext()) {
                    nextAction.append(new CheckEvo(it3.next(), null));
                }
            }
            nextAction.append(new WaitFrames(game, 58, new DisplayText.Clear(game, new SplitAction(new BattleFadeOut(game, null), new SplitAction(new BattleFadeOutMusic(game, null), new WaitFrames(game, 30, new SetField(game.musicController, "resumeOverworldMusic", true, null)))))));
            if (SpecialMewtwo1.class.isInstance(game.battle.oppPokemon)) {
                SpecialMewtwo1 mewtwo = (SpecialMewtwo1) game.battle.oppPokemon;
                mewtwo.tile.nameUpper = "mewtwo_overworld_hidden";
                mewtwo.tile.init();
                nextAction.append(new DisplayText(game, "MEWTWO fled... it may return when it' had time to recover.", (String) null, (Action) null, (Action) null));
            }
            if (game.battle.oppPokemon.standingAction != null) {
                game.battle.oppPokemon.removeDrawActions(game);
                game.battle.oppPokemon.standingAction = null;
                if (game.battle.oppPokemon.isTrapping) {
                    Tile tile = game.map.tiles.get(game.battle.oppPokemon.position);
                    if (tile.items != null) {
                        tile.items.remove(game.battle.oppPokemon.specie.name.toLowerCase(Locale.ROOT));
                    }
                } else {
                    game.map.pokemon.remove(game.battle.oppPokemon.position);
                }
            }
            nextAction.append(new SetField(game, "playerCanMove", true, null));
            game.insertAction(nextAction);
            return;
        }
        game.insertAction(this.nextAction);
    }
}
